package wxb.avalon.core.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import wxb.avalon.core.bean.Result;
import wxb.avalon.core.entity.dto.RoomPlayerDto;
import wxb.avalon.core.service.IRoomPlayerRoleService;
import wxb.avalon.core.service.IRoomService;
import wxb.avalon.core.util.RHUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxb
 * @since 2022-01-11
 */
@Controller
@RequestMapping("/core/roomPlayerRole")
public class RoomPlayerRoleController {

    @Autowired
    private IRoomService roomService;

    @GetMapping("/get/{roomNo}")
    @ResponseBody
    public Result<List<RoomPlayerDto>> get(HttpServletRequest req, @PathVariable String roomNo){
        Result<List<RoomPlayerDto>> result = new Result<>();
        try {
            Integer playerId = RHUtil.getPlayerId(req);
            if (null == playerId){
                return result.fail("请先登录");
            }
            return result.ok(roomService.getRoomPlayers(roomNo));
        }catch (Exception e){
            e.printStackTrace();
            return result.fail("系统异常："+e.getLocalizedMessage());
        }
    }

}
